﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace _16一对多;

public class CommentConfig:IEntityTypeConfiguration<Comment>
{
    public void Configure(EntityTypeBuilder<Comment> builder)
    {
        builder.ToTable("T_Comments");
        builder.Property(c => c.Message).IsRequired();
        builder.HasOne<Article>(c => c.Article)
            .WithMany(a => a.Comments)
            .HasForeignKey(c=>c.ArticleID)
            .IsRequired(false)
            .OnDelete(DeleteBehavior.NoAction);
        
    }
}